var member_id = ws = '';
document.addEventListener('plusready',function(){
	member_id = plus.storage.getItem('id');
	ws = plus.webview.currentWebview();
//	console.log(cart_id);
	$.ajax({ 
		type:"post", 
		url:apiRoot+"?act=member_cart&op=cart_list_old",
		data:{member_id:member_id},
		dataType:'json',
		success:function(data){ 
			console.log(JSON.stringify(data));
			if(data.datas.cart_list){
				var html = '';
				$.each(data.datas.cart_list, function(k,v) {
					html += '<div class="list-p">'+
								'<ul class="mui-table-view">'+
									'<li class="mui-table-view-cell mui-media" >'+
										'<div class="mui-pull-left wid1">'+
											'<div class="mui-checkbox mui-left">'+
												'<input name="checkbox" value="Item 1" type="checkbox"  class="goodip"  yuanprice = "'+ v.goods_sum +'" shu="'+ v.goods_num +'" data-store_id="'+ v.store_id +'" data-gwid="'+ v.cart_id +'">'+
											'</div>'+
										'</div>'+
										'<div class="mui-pull-left wid2 text shangping" >'+
											'<img class="mui-media-object mui-pull-left" src="'+ pics + v.store_id + '/' + v.goods_image +'">'+
											'<div class="mui-media-body">'+
												'<div class="mui-ellipsis-2">'+ v.goods_name +'</div>'+								
												'<p>'+
													'<span class="mui-h5 red">￥'+ v.goods_sum +'</span>'+
													'<span class="font10 mui-pull-right back">x'+ v.goods_num +'</span>'+
												'</p>'+
											'</div>'+
											'<div class="edit-text mui-text-center">'+
												'<div class="mui-numbox edit_goods" data-numbox-min="1">'+
													'<button class="mui-btn mui-btn-numbox-minus" type="button">-</button>'+
													'<input class="mui-input-numbox" type="number" value="'+ v.goods_num +'"/>'+
													'<button class="mui-btn mui-btn-numbox-plus" type="button">+</button>'+
												'</div>'+
											'</div>'+
										'</div>'+
									'</li>'+
								'</ul>'+
							'</div>'; 
				});
				$('.mui-content').html(html); 
			} 
			//子复选框的事件  
			$(".goodip").on('click', zixuankuang);
			/////////
			//mui +- 数量 失效 重写
			/////////////////////////////////
			$(".edit_goods button").on('click',function(){
				var bThis=$(this).parent();
				var bmin=parseInt(bThis.attr('data-numbox-min'));//设置最小值
				var bmax=parseInt(bThis.attr('data-numbox-max'));//设置最大值
				var binput=parseInt(bThis.find("input").val());//当前数量
				if($(this).text()=='+'){
					binput++
					bThis.find("input").val(binput>bmax?bmax:binput);
				}else{
					binput--
					bThis.find("input").val((binput<bmin)?bmin:binput);
				}
			})
		}, 
		error:function(e){
			toast('连接失败！');
		}
	});
},false);


//子复选框的事件  
function zixuankuang() {
    var chsub = $("input[type='checkbox'][class='goodip']").length; //获取subcheck的个数  
	var checkedsub = $("input[type='checkbox'][class='goodip']:checked").length; //获取选中的subcheck的个数  
	if(checkedsub == chsub) {
		$(".all-chose>input[type='checkbox']").prop("checked", true);    //全选
	} else {
		$(".all-chose>input[type='checkbox']").prop("checked", false);		//全不选
	}
    //获取选中的商品id
	var shu = 0; 
	var price = 0;
	$("input[type='checkbox'][class='goodip']:checked").each(function(){
		var price2 = parseFloat($(this).attr('yuanprice'));
    	var num =parseFloat($(this).attr('shu'));
    	shu = shu + 1;
    	price+=price2*num;

	})
	var money = price.toFixed(2);
	$('#total').text(money +'元');
	$('.Settlement').text('结算('+ shu +')');
}
